<?php
/**
 * Created by PhpStorm.
 * User: caipeichao
 * Date: 14-3-11
 * Time: PM3:34
 */

namespace Usercenter\Controller;
use Think\Controller;

class HouseController extends BaseController {
    public function my_chuzu($page=1,$uid=0) {
        //默认获取自己的主题列表

        if(!$uid) {
            $uid = is_login();
            $this->requireLogin();
        }
       $c=10;
        //获取我的主题列表
        $model = D('release_info');
        $map = array('uid'=>$uid,'status'=>1);
        $list = $model->where($map)->order('time desc')->page($page,$c)->select();
        $totalCount = $model->where($map)->count();
        $this->assign('pagenum',$c);

        //读取人称
        $call = $this->getCall($uid);

        //显示页面
        $this->defaultTabHash('my-chuzu');
        $this->assign('uid', $uid);
        $this->assign('totalCount',$totalCount);
        $this->assign('list',$list);
        $this->assign('call',$call);
        $this->display();
    }

    public function my_qiuzu($page=1,$uid=0) {
        //默认获取自己的主题列表
        if(!$uid) {
            $uid = is_login();
            $this->requireLogin();
        }
       $c=10;
        //获取我的主题列表
        $model = D('qiuzu_info');
        $map = array('uid'=>$uid,'status'=>1);
        $list = $model->where($map)->order('time desc')->page($page,$c)->select();
        $totalCount = $model->where($map)->count();
        $this->assign('pagenum',$c);
        //读取人称
        $call = $this->getCall($uid);

        //显示页面
        $this->defaultTabHash('my-qiuzu');
        $this->assign('uid', $uid);
        $this->assign('totalCount',$totalCount);
        $this->assign('list2',$list);
        $this->assign('call',$call);
        $this->display();
    }
    //我的出租的删除和编辑
    public function  delete_chuzu($id){

    $map['id']=$id;

       $result= D('release_info')->where('id='.$id)->delete();
     if($result){
       $this->success('删除成功！',U('UserCenter/House/my_chuzu'));
    }else{
            $this->error('删除失败',U('UserCenter/House/my_chuzu'));
     }


}
    public function  edit_chuzu($id){

        $map['id']=$id;
        $Model=D('release_info');
        $result=$Model->where($map)->find();

        $this->assign('result',$result);


        $this->display();

        /*if($result){
            $this->success('删除成功！',U('UserCenter/House/my_chuzu'));
        }else{
            $this->error('删除失败',U('UserCenter/House/my_chuzu'));
        }*/


    }

        public function save_edit_chuzu($id,$position,$orientation,$village,$title,$nickname,$phone,$description,$price,$type,$area,$style,$configure,$mold){

            /*判断表单输入是否为空*/
            empty($style) && $this->error('请选择出租形式');
            empty($position) && $this->error('请填写地区');
            empty($village) && $this->error('请填写小区');
            empty($type) && $this->error('请填写户型');
            empty($area) && $this->error('请填写面积');
            empty($price) && $this->error('请填写租金');
            empty($orientation) && $this->error('请选择朝向');
            empty($mold) && $this->error('请选择房屋类型');
            empty($configure) && $this->error('请填写配置');
            empty($title) && $this->error('请填写标题');
            empty($description) && $this->error('请填写描述');
            empty($nickname) && $this->error('请填写联系人');
            empty($phone) && $this->error('请填写联系电话');

            //preg_match_all('/\[(.*?)\]/',$photo,$photo1);
            /*判断照片至少是3张*/
            //count($photo1[1]) < 3 && $this->error('请至少上传3张照片');
            /*获取数据表字段对应值*/

            //$user_auth=session('user_auth');
            //$data['uid']=$user_auth['uid'];
            $data['style']=$_POST['style'];
            $data['position']=$position;
            $data['orientation']=$orientation;
            $data['village']=$village;
            $data['title']=$title;
            $data['nickname']=$nickname;
            $data['configure']=$configure;
            $data['price']=$price;
            $data['type']=$type;
            $data['mold']=$mold;
            //$data['photo']=$photo;
            $data['description']=str_replace(array("\n" , " " ) , array("<br>","&nbsp;") ,$description);
            $data['phone']=$phone;
            $data['area']=$area;
            $data['time']=time();
            $data['id']=$id;
            /*写入数据表*/
            // $map['id']=$id;

            $res =  D('release_info')->save($data);

            if($res){


                $this->success('修改成功',U('Usercenter/House/my_chuzu'));

            }
            else{
                $this->error('修改失败',U('Usercenter/House/my_chuzu'));
            }
        }
















    //我的求租的编辑和删除
    public function  delete_qiuzu($id){

        $map['id']=$id;

        $result= D('qiuzu_info')->where('id='.$id)->delete();
        if($result){
            $this->success('删除成功！',U('UserCenter/House/my_qiuzu'));
        }else{
            $this->error('删除失败',U('UserCenter/House/my_qiuzu'));
        }


    }
    public function  edit_qiuzu($id){

        $map['id']=$id;
        $Model=D('qiuzu_info');
        $result=$Model->where($map)->find();

        $this->assign('result',$result);


        $this->display();

        /*if($result){
            $this->success('删除成功！',U('UserCenter/House/my_chuzu'));
        }else{
            $this->error('删除失败',U('UserCenter/House/my_chuzu'));
        }*/


    }

    public function save_edit_qiuzu($id,$position,$village,$title,$nickname,$phone,$description,$price_min,$price_max,$type){

        /*判断表单输入是否为空*/

        empty($position) && $this->error('请填写地区');
        //empty($village) && $this->error('请填写小区');
        empty($type) && $this->error('请填写户型');

        empty($price_min) && $this->error('请填写最小租金');
        empty($price_min) && $this->error('请填写最大租金');

        empty($title) && $this->error('请填写标题');
        empty($description) && $this->error('请填写描述');
        empty($nickname) && $this->error('请填写联系人');
        empty($phone) && $this->error('请填写联系电话');

        //preg_match_all('/\[(.*?)\]/',$photo,$photo1);
        /*判断照片至少是3张*/
        //count($photo1[1]) < 3 && $this->error('请至少上传3张照片');
        /*获取数据表字段对应值*/

        $user_auth=session('user_auth');
        //$data['uid']=$user_auth['uid'];

        $data['position']=$position;

        $data['village']=$village;
        $data['title']=$title;
        $data['nickname']=$nickname;
        $data['price_min']=$price_min;
        $data['price_max']=$price_max;
        $data['type']=$type;

        $data['description']=str_replace(array("\n" , " " ) , array("<br>","&nbsp;") ,$description);
        $data['phone']=$phone;

        $data['time']=time();
        $data['id']=$id;
        /*写入数据表*/
        // $map['id']=$id;

        $res =  D('qiuzu_info')->save($data);

        if($res){
            $this->success('修改成功',U('Usercenter/House/my_qiuzu'));

        }
        else{
            $this->error('修改失败',U('Usercenter/House/my_qiuzu'));
        }

    }


    /* public function myBookmark($page=1) {
              //要求已经登录
              $this->requireLogin();

              //获取自己的UID
              $uid = is_login();

              //读取数据库获取已经收藏的帖子
              $map = array('uid'=>$uid);
              $model = D('ForumBookmark');
              $list = $model->where($map)->order('create_time desc')->page($page)->select();
              $totalCount = $model->where($map)->count();

              //读取帖子的详情
              foreach($list as &$e) {
                  $e = D('ForumPost')->where(array('id'=>$e['post_id']))->find();
              }

              //显示页面
              $this->defaultTabHash('my-bookmark');
              $this->assign('totalCount', $totalCount);
              $this->assign('list', $list);
              $this->assign('call', $this->getCall($uid));
              $this->display();
          }*/
}
































